import 'package:equatable/equatable.dart';

import 'BaseBloc.dart';

final class DraggableCubit extends BaseBloc<DraggableEvent, DraggableState> {

  DraggableCubit() : super(const DraggableState.init()) {
    on<DraggableMoveEvent>((event, emit) {
      double x = state.leftPosition + event.mx;
      double y = state.topPosition + event.my;
      emit(DraggableState.success(x, y));
    });
  }
}

final class DraggableState extends Equatable {

  final double leftPosition;
  final double topPosition;

  const DraggableState._({
    this.leftPosition = 0,
    this.topPosition = 0,
  });

  const DraggableState.init() : this._();

  const DraggableState.success(double x, double y) : this._(leftPosition: x, topPosition: y);

  @override
  List<Object?> get props => [leftPosition, topPosition];

}

class DraggableEvent {}
class DraggableMoveEvent extends DraggableEvent {
  final double mx;
  final double my;
  DraggableMoveEvent(this.mx, this.my);

}